//
//  WeekViewController.m
//  Gxj
//
//  Created by 刘伟 on 2017/10/24.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "WeekViewController.h"
#import "PagedFlowView.h"
#import "LeaderboardFromTableViewCell.h"
#import "LeaderboardCellHeadFromView.h"

@interface WeekViewController ()<PagedFlowViewDelegate,PagedFlowViewDataSource,UITableViewDelegate,UITableViewDataSource>
{
    PagedFlowView *_flowView;
    LeaderboardCellHeadFromView *_cellHeadView;
}
@property (nonatomic,strong) NSArray *viewArray;
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) UITableView *tableView1;
@property (nonatomic,strong) UITableView *tableView2;
@property (nonatomic,strong) UITableView *tableView3;

@end

@implementation WeekViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithRed:242.0/255.0 green:242.0/255.0 blue:242.0/255.0 alpha:1];
    
    [self showWeekViewController];
}

- (void)showWeekViewController
{
    _flowView =[[PagedFlowView alloc] initWithFrame:CGRectMake(kWidthScale(20), kHeightScale(20), UIScreenWidth - kWidthScale(40), kHeightScale(418))];
    _flowView.delegate = self;
    _flowView.dataSource = self;
    _flowView.minimumPageAlpha = 0.3;
    _flowView.minimumPageScale = 0.9;
//    _flowView.backgroundColor = [UIColor redColor];
    self.viewArray = @[self.tableView,self.tableView1,self.tableView2,self.tableView3];
    [self.view addSubview:_flowView];
    
    _cellHeadView = [[LeaderboardCellHeadFromView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.size.width, kHeightScale(159))];
    self.tableView2.tableHeaderView = _cellHeadView;
    _cellHeadView = [[LeaderboardCellHeadFromView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.size.width, kHeightScale(159))];
    self.tableView1.tableHeaderView = _cellHeadView;
    _cellHeadView = [[LeaderboardCellHeadFromView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.size.width, kHeightScale(159))];
    self.tableView.tableHeaderView = _cellHeadView;
    _cellHeadView = [[LeaderboardCellHeadFromView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.size.width, kHeightScale(159))];
    self.tableView3.tableHeaderView = _cellHeadView;
    
    self.tableView .tableFooterView = [[UIView alloc] init];
    self.tableView1.tableFooterView = [[UIView alloc] init];
    self.tableView2.tableFooterView = [[UIView alloc] init];
    self.tableView3.tableFooterView = [[UIView alloc] init];
}

#pragma mark pagedFlowView data source
- (NSInteger)numberOfPagesInFlowView:(PagedFlowView *)flowView{
    return self.viewArray.count;
}


- (UIView *)flowView:(PagedFlowView *)flowView cellForPageAtIndex:(NSInteger)index{
    UIView *view = (UIView *)[flowView dequeueReusableCell];
    if(!view){
        view = [[UIView alloc] init];
    }
    [view addSubview:self.viewArray[index]];
    return view;
}

//- (CGSize)sizeForPageInFlowView:(PagedFlowView *)flowView
//{
//
//}

#pragma mark - tableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return kHeightScale(55);
}

#pragma mark - tableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LeaderboardFromTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"showLeaderboard"];
    switch (tableView.tag) {
        case 111111:
            if (!cell) {
                cell = [[LeaderboardFromTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"showLeaderboard"];
            }
            
            break;
            
        case 222222:
            if (!cell) {
                cell = [[LeaderboardFromTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"showLeaderboard"];
            }
            
            break;
            
        case 333333:
            if (!cell) {
                cell = [[LeaderboardFromTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"showLeaderboard"];
            }
            
            break;
            
        case 444444:
            if (!cell) {
                cell = [[LeaderboardFromTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"showLeaderboard"];
            }
            
            break;
            
        default:
            break;
    }
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWidthScale(275), _flowView.size.height) style:UITableViewStylePlain];
        
        _tableView.tag = 111111;
        
        _tableView.delegate = self;
        
        _tableView.dataSource = self;
    }
    return _tableView;
}

- (UITableView *)tableView1
{
    if (!_tableView1)
    {
        _tableView1 = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWidthScale(275), _flowView.size.height) style:UITableViewStylePlain];
        
        _tableView1.tag = 222222;
        
        _tableView1.delegate = self;
        
        _tableView1.dataSource = self;
    }
    return _tableView1;
}

- (UITableView *)tableView2
{
    if (!_tableView2)
    {
        _tableView2 = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWidthScale(275), _flowView.size.height) style:UITableViewStylePlain];
        
        _tableView2.tag = 333333;
        
        _tableView2.delegate = self;
        
        _tableView2.dataSource = self;
    }
    return _tableView2;
}

- (UITableView *)tableView3
{
    if (!_tableView3)
    {
        _tableView3 = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWidthScale(275), _flowView.self.height) style:UITableViewStylePlain];
        
        _tableView3.tag = 444444;
        
        _tableView3.delegate = self;
        
        _tableView3.dataSource = self;
    }
    return _tableView3;
}

@end
